home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / ultra250.zip / UW_DEMO.C < prev    next >
Text File  |  1992-11-12  |  45KB  |  1,306 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* UW_DEMO.C                                                                                                                            */
  4. /*                                                                                                                    Kevin Huck            */
  5. /*                                                                                                                    Boyd Gafford        */
  6. /*                                                                          */
  7. /*   This demo program will show you many of the capabilities of UltraWin   */
  8. /* version 2.50.  See the documentation for a complete function listing.    */
  9. /*                                                                          */
  10. /* NOTE:                                                                    */
  11. /*   This file has a tab size of 2, and can be compiled and linked under    */
  12. /*   small model.                                                           */
  13. /*                                                                          */
  14. /****************************************************************************/
  15. #include <stdlib.h>
  16. #include <dos.h>
  17. #include <stdio.h>
  18. #include <ctype.h>
  19. #include <conio.h>
  20. #include <time.h>
  21. #ifdef M_I86
  22.     #include <malloc.h>
  23. #else
  24.     #include <alloc.h>
  25. #endif
  26. #include "uw.h"
  27.  
  28. #define NUM_WINS 26
  29.  
  30. typedef struct fields_struct                        /* structure for field input to the    */
  31. {                                                                                /* order form function!                            */
  32.     int        num_fields;                                            /* total number of fields                        */
  33.     char    *input[10];                     /* strings for the result                        */
  34.     char    *mask[10];                      /* masks for display on the screen    */
  35.     char    *t[10];                                    /* templates for validation                    */
  36.     int        x[10];                          /* positions for the input                    */
  37.     int        y[10];
  38.     int        strip[10];                      /* strip masks on result?                        */
  39. } FIELDS;
  40.  
  41. /*----------------- global variables for the demo program ------------------*/
  42. WINDOW    Main_wn, Print_wn[2];
  43. WINDOW     Back_wn, *Back_wnp = &Back_wn;
  44. MENU        Top_menu, *Top_mnp = &Top_menu;
  45. MENU    Terminal_menu, Setup_menu, Window_menu, Files_menu;
  46. MENU        *Drop_mnps[4];
  47.  
  48. uchar     *Font8x14;
  49. PRINT     Printer1, Printer2;
  50. char         *Enque_strs[] =
  51.                 {
  52.                     "EnQue Software",
  53.                     "Route 1, Box 116C",
  54.                     "Pleasant Hill, MO, 64080",
  55.                     "24-Hour BBS (816) 353-0991",
  56.                     "Voice/Fax (816) 987-2515",
  57.                     "(Voice 5-10pm and weekends)"
  58.                 };
  59. char        Name[40], Address[40], City[30], State[10],
  60.                 Zip[10], Phone[20], Password[10];
  61. int         Wait_for_key = 1;
  62.  
  63.  
  64. /*------------------------ prototypes for the program ----------------------*/
  65. void wn_3d_plst( int c, int r, char *str, WINDOW *wnp );
  66. void wn_line_demo( void );
  67. void wn_entry_demo( void );
  68. void wn_color_demo( void );
  69. void wn_create_demo( void );
  70. void wn_scroll_demo( void );
  71. void wn_prompt( char *prompt, int mode );
  72. void wait( int mode );
  73. void title_screen( void );
  74. int  wn_menu_demo( void );
  75. int  background_func( void );
  76. void wn_change_att( uchar new_att, uchar old_att, WINDOW *wnp );
  77. void wn_font_demo( void );
  78. void wn_print_demo( void );
  79. void disp_print_stats( PRINT *p, int mode, WINDOW *wnp );
  80.  
  81.  
  82. /*********/
  83. /* ~main */
  84. /*       ********************************************************************/
  85. /****************************************************************************/
  86. void main()
  87. {
  88.     int r, end_flag = 0;
  89.     WINDOW *wnp;
  90.  
  91.     init_video(80, 25);
  92.     init_mouse();
  93.     init_clock(0x3333);
  94.     wnp = &Main_wn;
  95.     wn_create( 0, 3, V_cols-1, V_rows-1, NO_BDR, WN_NORMAL, wnp );
  96.     wn_color( CYAN, BLUE, wnp );
  97.     wn_bdr_color( YELLOW, BLUE, wnp );
  98.     wn_name("Main_wn", wnp);
  99.     link_window(wnp);
  100.     title_screen();
  101.     wn_plst( CENTERED, (V_rows / 2) - 1,
  102.          "Welcome to the UltraWin Library!", wnp );
  103.     if( Ega )
  104.         wn_plst( CENTERED, 3,
  105.              "UltraWin detects the presence of an EGA compatible board", wnp);
  106.     else if( Vga )
  107.         wn_plst( CENTERED, 3,
  108.              "UltraWin detects the presence of a VGA compatible board", wnp);
  109.     wait(0);
  110.  
  111.     wn_clear(wnp);
  112.     wn_color( BLUE, LIGHTGRAY, wnp );
  113.  
  114.     wn_plst(1, 0, "    Speed it one of many features incorporated into the UltraWin Library.     ", wnp );
  115.     wn_plst(1, 1, "   Here is a list of the main features, all of which will be demonstrated!    ", wnp );
  116.  
  117.     wn_color( YELLOW, BLUE, wnp );
  118.     wn_hline(2,SGL_BDR,wnp);
  119.     r = 3;
  120.     wn_plst(0, r++, "1) Complete range of windowing functions to dynamically create, update,", wnp );
  121.     wn_plst(0, r++, "   move, and destroy an unlimited number of windows.", wnp );
  122.     wn_color( WHITE, BLUE, wnp );
  123.     wn_plst(0, r++, "2) A Window Manager that will handle all the hard work when multiple", wnp );
  124.     wn_plst(0, r++, "   windows are on the screen.", wnp );
  125.     wn_color( YELLOW, BLUE, wnp );
  126.     wn_plst(0, r++, "3) Each window is fully buffered. Output to a window can take place at any", wnp );
  127.     wn_plst(0, r++, "   time, even if another window overlaps it.  This is perhaps, the", wnp );
  128.     wn_plst(0, r++, "   most impressive feature. Windows can scroll output even if overlapped!", wnp );
  129.     wn_color( WHITE, BLUE, wnp );
  130.     wn_plst(0, r++, "4) Powerful string and data entry capabilities.", wnp );
  131.     wn_color( YELLOW, BLUE, wnp );
  132.     wn_plst(0, r++, "5) Powerful menuing capability with full mouse support!", wnp );
  133.     wn_color( WHITE, BLUE, wnp );
  134.     wn_plst(0, r++, "6) The library supports virtually any video board, including 43/50", wnp );
  135.     wn_plst(0, r++, "   row EGA/VGA mode. It even works with non-standard modes i.e. 132*60.", wnp );
  136.     wn_color( YELLOW, BLUE, wnp );
  137.     wn_plst(0, r++, "7) UltraWin now works in EGA/VGA graphics mode and has user defined", wnp );
  138.     wn_plst(0, r++, "   font capability in both text and graphics modes!", wnp );
  139.     wn_color( WHITE, BLUE, wnp );
  140.     wn_plst(0, r++, "8) EGA/VGA palette control and blink enable/disable to allow all 16", wnp );
  141.     wn_plst(0, r++, "   background colors without foreground blinking.", wnp );
  142.     wn_color( YELLOW, BLUE, wnp );
  143.     wn_plst(0, r++, "9) UltraWin also has dynamic printer queues that can be either ram", wnp );
  144.     wn_plst(0, r++, "   or disked based and can print to multiple devices in the background!", wnp );
  145.     wn_hline(r,SGL_BDR,wnp);
  146.     wait(0);
  147.  
  148.     while( !end_flag )
  149.     {
  150.         wn_clear(wnp);
  151.         wn_color( BLUE, LIGHTGRAY, wnp );
  152.         r = 3;
  153.         wn_3d_plst(13, r++, "A) Color/Palette Control", wnp ), r++;
  154.         wn_3d_plst(13, r++, "B) Window Creation      ", wnp ), r++;
  155.         wn_3d_plst(13, r++, "C) Text Line Drawing    ", wnp ), r++;
  156.         wn_3d_plst(13, r++, "D) Window Scrolling     ", wnp ), r++;
  157.         wn_3d_plst(13, r++, "E) Data Entry           ", wnp ), r++;
  158.         r = 3;
  159.         wn_3d_plst(43, r++, "F) Drop-down Menus      ", wnp ), r++;
  160.         wn_3d_plst(43, r++, "G) EGA/VGA Text Fonts   ", wnp ), r++;
  161.         wn_3d_plst(43, r++, "H) Print Capabilities   ", wnp ), r++;
  162.         wn_3d_plst(43, r++, "I) All of the Above     ", wnp ), r++;
  163.         wn_color( RED, LIGHTGRAY, wnp );
  164.         wn_3d_plst(43, r++, "J) Quit Demo  <<Esc>>   ", wnp ), r++;
  165.         wn_color( BLUE, LIGHTGRAY, wnp );
  166.         if( Wait_for_key )
  167.             wn_3d_plst(13, r++, "K) Key press requirement between operations  : ON     ", wnp ), r++;
  168.         else
  169.             wn_3d_plst(13, r++, "K) Key press requirement between operations  : OFF    ", wnp ), r++;
  170.         r++;
  171.  
  172.         wn_prompt("Select desired demo to execute...", 1);
  173.         wn_color( LIGHTGRAY, BLUE, wnp );
  174.         switch( toupper(Event.key) )
  175.         {
  176.             case 'Q': case 'J':    case 27: end_flag = 1; break;
  177.  
  178.             case 'A': wn_color_demo();  break;
  179.             case 'B': wn_create_demo(); break;
  180.             case 'C': wn_line_demo();   break;
  181.             case 'D': wn_scroll_demo(); break;
  182.             case 'E': wn_entry_demo();  break;
  183.  
  184.             case 'F': wn_menu_demo();   break;
  185.             case 'G': wn_font_demo();   break;
  186.             case 'H': wn_print_demo();  break;
  187.  
  188.             case 'I':
  189.                 wn_color_demo();
  190.                 wn_create_demo();
  191.                 wn_line_demo();
  192.                 wn_scroll_demo();
  193.                 wn_entry_demo();
  194.                 wn_menu_demo();
  195.                 wn_font_demo();
  196.                 wn_print_demo();
  197.                 break;
  198.             case 'K': Wait_for_key = !Wait_for_key; break;
  199.         }
  200.     }
  201.     wn_destroy(wnp);
  202.     end_clock();
  203.     end_mouse();
  204.     end_video();
  205.     exit(0);
  206. }
  207. /*** end of main ***/
  208.  
  209. /***************/
  210. /* ~wn_3d_plst */
  211. /*             **************************************************************/
  212. /* This is specifically for the demo menu....                               */
  213. /****************************************************************************/
  214. void wn_3d_plst( int c, int r, char *str, WINDOW *wnp )
  215. {
  216.     push(wnp->att);
  217.     wn_color( BLACK, BLUE, wnp );
  218.     mv_cs( c + 1, r + 1, wnp );
  219.     wn_qch( strlen(str), 223, wnp );
  220.     mv_cs( c + strlen(str), r, wnp );
  221.     wn_ch(220, wnp);
  222.     pop(wnp->att);
  223.     wn_plst( c, r, str, wnp );
  224. }
  225. /*** end of wn_3d_plst ***/
  226.  
  227. /*****************/
  228. /* ~wn_line_demo */
  229. /*               ************************************************************/
  230. /****************************************************************************/
  231. void wn_line_demo( void )
  232. {
  233.     int i, t, x, y;
  234.     WINDOW wn;
  235.  
  236.  
  237.     wn_clear(&Main_wn);
  238.     /*----------------- demonstrate line drawing capabilities ----------------*/
  239.     wn_prompt("UltraWin has several border styles...",0);
  240.     wn_create( 17, 7, 59, 19, SGL_BDR, WN_POPUP, &wn );
  241.     wn_color( BLACK, CYAN, &wn );
  242.     wn_bdr_color( BLACK, CYAN, &wn );
  243.     link_window(&wn);
  244.     for( t = 0; t < 3; t++ )
  245.     {
  246.         for( i = 0; i <= 4; i++ )
  247.         {
  248.             wn_set_bdr_style(i, &wn);
  249.             wn_border(&wn);
  250.             wait_ticks( 4L );
  251.         }
  252.     }
  253.     wn_prompt("UltraWin has line drawing capabilities....",0);
  254.     wn_set_bdr_style(SGL_BDR,&wn);
  255.     wn_border(&wn);
  256.  
  257.     wn_hline(2,DBL_BDR,&wn);
  258.     wait_ticks(  4L );
  259.     wn_hline(4,SGL_BDR,&wn);
  260.     wait_ticks(  4L );
  261.     wn_vline(4,DBL_BDR,&wn);
  262.     wait_ticks(  4L );
  263.     wn_hline(8,DBL_BDR,&wn);
  264.     wait_ticks(  4L );
  265.     wn_vline(40,SGL_BDR,&wn);
  266.     wait_ticks(  4L );
  267.     wn_hline(6,SGL_BDR,&wn);
  268.     wait_ticks(  4L );
  269.     wn_vline(22,SGL_BDR,&wn);
  270.     wait_ticks(  4L );
  271.     wait(0);
  272.     wn_clear(&wn);
  273.     wn_border(&wn);
  274.     wn_color( YELLOW, CYAN, &wn );
  275.     wn_color( RED, CYAN, &wn );
  276.     wn_plst( 0, 1, "  1     2     3     4     5     6     7 ", &wn );
  277.     wn_plst( 0, 4, "  8     9    10    11    12    13    14 ", &wn );
  278.     wn_plst( 0, 7, " 15     16   17    18    19    20    21 ", &wn );
  279.     wn_plst( 0,10, " 22     23   24    25    26    27    28 ", &wn );
  280.     wn_color( BLACK, CYAN, &wn );
  281.     for( x = 5; x < 40; x += 6 )
  282.         wn_vline(x, SGL_BDR, &wn);
  283.     for( y = 2; y < 11; y += 3 )
  284.         wn_hline(y, SGL_BDR, &wn);
  285.     wn_color( BLUE, LIGHTGRAY, &wn );
  286.     wn_set_inside(0, &wn);
  287.     wn_plst( 0, 0, "   S     M     T     W     T     F     S   ", &wn );
  288.     wn_set_inside(1, &wn);
  289.     wait(0);
  290.     unlink_window(&wn);
  291.     wn_destroy(&wn);
  292. }
  293. /*** end of wn_line_demo ***/
  294.  
  295. /******************/
  296. /* ~wn_entry_demo */
  297. /*                ***********************************************************/
  298. /****************************************************************************/
  299. void wn_entry_demo( void )
  300. {
  301.     int            i, stat, end_flag = OFF;
  302.     uchar        m_att = ((CYAN << 4) | YELLOW),
  303.                     w_att = ((CYAN << 4) | WHITE),
  304.                     bdr_att = ((CYAN << 4) | BLACK);
  305.     WINDOW    wn, *wnp = &wn;
  306.     FIELDS    f;
  307.  
  308.     wn_clear(&Main_wn);
  309.     /*--------------------- demonstrate entry capabilities -------------------*/
  310.     wn_prompt("UltraWin has flexible data entry support...",0);
  311.  
  312.     f.input[0]        = Name;
  313.     f.x[0]                = 23, f.y[0] = 10, f.strip[0] = ON;
  314.     f.mask[0]            = "___________________________________";
  315.     f.t[0]          = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
  316.   f.input[1]        = Address;
  317.     f.x[1]                = 23, f.y[1] = 11, f.strip[1] = ON;
  318.     f.mask[1]     = "___________________________________";
  319.     f.t[1] =              "***********************************";
  320.     f.input[2]        = City;
  321.     f.x[2]                = 23, f.y[2] = 12, f.strip[2] = ON;
  322.     f.mask[2]     = "____________________";
  323.   f.t[2]              = "UAAAAAAAAAAAAAAAAAAA";
  324.   f.input[3]        = State;
  325.     f.x[3]                = 52, f.y[3] = 12, f.strip[3] = ON;
  326.     f.mask[3]     = "__";
  327.     f.t[3]        = "UU";
  328.     f.input[4]        = Zip;
  329.     f.x[4]                = 62, f.y[4] = 12, f.strip[4] = ON;
  330.     f.mask[4]     = "_____";
  331.     f.t[4]        = "#####";
  332.     f.input[5]        = Phone;
  333.     f.x[5]                = 23, f.y[5] = 13, f.strip[5] = OFF;
  334.     f.mask[5]     = "(___) ___-____";
  335.     f.t[5]        = " ###  ### ####";
  336.     f.input[6]        = Password;
  337.     f.x[6]                = 23, f.y[6] = 14, f.strip[6] = ON;
  338.     f.mask[6]     = "________";
  339.     f.t[6]        = "AAAAAAAA";
  340.  
  341.     wn_create(2, 4, 77, 23, DBL_BDR, WN_NORMAL, wnp);
  342.     wn_bdratt(bdr_att,wnp);
  343.     wn_att(w_att,wnp);
  344.     wn_name("< UltraWin Order Form >", wnp);
  345.     m_hide();
  346.     link_window(wnp);
  347.     for (i=0; i<6; i++)
  348.         wn_plst(2, i + 1, Enque_strs[i], wnp);
  349.  
  350.     wn_plst(4,   8, "Yes, I want to order UltraWin at $99.95.  Please mail to:", wnp);
  351.     wn_plst(10, 10, "        Name:", wnp);
  352.     wn_plst(10, 11, "     Address:", wnp);
  353.     wn_plst(10, 12, "        City:                      State:    Zip:", wnp);
  354.     wn_plst(10, 13, "       Phone:", wnp);
  355.     wn_plst(10, 14, "BBS Password:", wnp);
  356.  
  357.     wn_att(m_att,wnp);
  358.     for (i=0; i<7; i++)
  359.     {
  360.         wn_plst(f.x[i], f.y[i], f.mask[i], wnp);
  361.         wn_plst(f.x[i], f.y[i], f.input[i], wnp);
  362.     }
  363.     wn_plst(6, 17, "Please enter the following fields, pressing PgDn when complete", wnp);
  364.     wn_att(m_att,wnp);
  365.     f.num_fields = 7;
  366.     wn_att(bdr_att,wnp);
  367.     wn_plst(38, 1, "UltraWin Libraries + Source", wnp);
  368.     wn_plst(38, 2, "  1) Large Model Libraries", wnp);
  369.     wn_plst(38, 3, "  2) Printed Documentation", wnp);
  370.     wn_plst(38, 4, "  3) Example Programs", wnp);
  371.     wn_plst(38, 5, "  4) Support Via the EnQue BBS", wnp);
  372.     wn_plst(38, 6, "  5) Full Source Code!", wnp);
  373.     wn_att(w_att,wnp);
  374.     m_show();
  375.     i = 0;
  376.     while (!end_flag)
  377.     {
  378.         mv_cs(f.x[i], f.y[i], wnp);
  379.         stat = wn_gets(f.input[i], f.mask[i], f.t[i], m_att, f.strip[i], wnp);
  380.         switch( stat )
  381.         {
  382.             case KEY_UP:
  383.                 if (--i < 0)
  384.                     i = f.num_fields - 1;
  385.                 break;
  386.             case KEY_ENTER:
  387.                 if (++i >= f.num_fields)
  388.                   end_flag = ON;
  389.                 break;
  390.             case KEY_DN: case KEY_TAB:
  391.                 if (++i >= f.num_fields)
  392.                     i = 0;
  393.               break;
  394.             case KEY_PGUP: case KEY_PGDN:
  395.             case KEY_ESC: case -1:
  396.                 end_flag = ON;
  397.                 break;
  398.         }
  399.     }
  400.     m_hide();
  401.     unlink_window(wnp);
  402.     wn_destroy(wnp);
  403.     m_show();
  404. }
  405. /*** end of wn_entry_demo ***/
  406.  
  407. /******************/
  408. /* ~wn_color_demo */
  409. /*                ***********************************************************/
  410. /****************************************************************************/
  411. void wn_color_demo( void )
  412. {
  413.     int i, x, xs, ys;
  414.     char buff[81];
  415.     uchar palette[16], new_att, old_att;
  416.     WINDOW *wns[8], *wnp;
  417.     static char *names[8] = { "<< Window 0 >>", "<< Window 1 >>",
  418.      "<< Window 2 >>", "<< Window 3 >>", "<< Window 4 >>",
  419.      "<< Window 5 >>", "<< Window 6 >>", "<< Window 7 >>" };
  420.  
  421.     wn_clear(&Main_wn);
  422.     wn_prompt("Let's demonstrate UltraWin's color capabilities...",0);
  423.     for( i = 0; i < 8; i++ )
  424.         wns[i] = (WINDOW *) calloc(1, sizeof(WINDOW));
  425.     for( i = 0; i < 8; i++ )
  426.     {
  427.         wnp = wns[i];
  428.         xs = i * 3 + 12, ys = i + 5;
  429.         wn_create( xs, ys, xs + 31, ys + 9, SGL_BDR, WN_NORMAL, wnp );
  430.         wn_color( WHITE,  i % 8, wnp );
  431.         wn_bdr_color( WHITE, i % 8, wnp );
  432.         sprintf(buff, "<< Window %d >>", i + 1 );
  433.         wn_name(names[i], wnp);
  434.         link_window(wnp);
  435.         for( x = 0; x < 8; x++ )
  436.         {
  437.             sprintf(buff, "Window %d, Line %d", i, x );
  438.             wn_plst( 0, x, buff, wnp );
  439.         }
  440.     }
  441.     for( x = 0; x < 32; x++ )
  442.     {
  443.         for( i = 0; i < 8; i++ )
  444.         {
  445.             new_att = ((((x + i + 1) % 8)) << 4) | WHITE;
  446.             old_att = (((x + i) % 8) << 4) | WHITE;
  447.             wn_bdratt(new_att, wns[i]);
  448.             wn_change_att( new_att, old_att, wns[i] );
  449.         }
  450.     }
  451.     wn_prompt("We can bring any window to the Top...",0);
  452.     for( i = 7; i >= 0; i-- )
  453.         make_top_window(wns[rand()%7]);
  454.     for( i = 7; i >= 0; i-- )
  455.         make_top_window(wns[i]);
  456.     if( EgaVga )
  457.     {
  458.         wn_prompt("We can change the EGA/VGA palette registers...",0);
  459.         read_palette_all(palette);
  460.         for( i = 0; i < 32; i++ )
  461.             write_palette(rand() % 16, (uchar) (rand() % 64)), wait_ticks(2L);
  462.         write_palette_all(palette);
  463.     }
  464.     for( i = 0; i < 8; i++ )
  465.     {
  466.         unlink_window(wns[i]);
  467.         wn_destroy(wns[i]);
  468.     }
  469. }
  470. /*** end of wn_color_demo ***/
  471.  
  472. /*******************/
  473. /* ~wn_create_demo */
  474. /*                 **********************************************************/
  475. /****************************************************************************/
  476. char Ww_str[320];
  477. char *Ww_strs[] =
  478. {
  479. "UltraWin has powerful text output support including word wrap and special ",
  480. "character processing.  Newlines, carriage returns, tabs, backspaces, and ",
  481. "the bell character can all be independently enabled.  For improved ",
  482. "performance, output routines that do not perform these tasks are available."
  483. };
  484. void wn_create_demo( void )
  485. {
  486.     int i, j, x, xs, ys, xe, ye;
  487.     char buff[81];
  488.     WINDOW *wns[NUM_WINS], *wnp;
  489.     WINDOW wn;
  490.  
  491.     for( i = 0; i < 4; i++ )
  492.         strcat(Ww_str, Ww_strs[i]);
  493.     wn_color( YELLOW, BLUE, &Main_wn );
  494.     wn_clear(&Main_wn);
  495.     for( i = 0; i < 10; i++ )
  496.     {
  497.         mv_cs(20, i + 4, &Main_wn);
  498.         wn_printf(&Main_wn, "This is line %d........", i + 1 );
  499.     }
  500.     wn_prompt("Let's dynamically allocate, create, and set 26 POPUP windows.",0);
  501.     for( x = 0; x < NUM_WINS; x++ )
  502.         if( (wns[x] = (WINDOW *) calloc(1, sizeof(WINDOW))) == NULL )
  503.             return;
  504.     x = 0;
  505.     for( i = 0; i < 5; i++ )
  506.     {
  507.         for( j = 0; j < 4; j++, x++ )
  508.         {
  509.             switch( j )
  510.             {
  511.                 case 0: xs =      i * 6; ys =      i + 3; break;
  512.                 case 1: xs = 60 - i * 6; ys =      i + 3; break;
  513.                 case 2: xs =      i * 6; ys = 20 - i;         break;
  514.                 case 3: xs = 60 - i * 6; ys = 20 - i;          break;
  515.             }
  516.             wnp = wns[x];
  517.             wn_create( xs, ys, xs + 19, ys + 5, SGL_BDR, WN_POPUP,wnp );
  518.             wn_color( WHITE, j + 2, wnp );
  519.             wn_bdr_color( WHITE, j + 2, wnp );
  520.             sprintf(buff, "<< Window %d >>", x + 1 );
  521.             wn_name(buff, wnp);
  522.             wn_set(wnp);
  523.             wn_plst(CENTERED, 0, buff, wnp);
  524.         }
  525.     }
  526.     for( i = 0; i < 12; i += 2, x++ )
  527.     {
  528.         wnp = wns[x];
  529.         xs = 32 - i * 2, ys = 12 - i / 2;
  530.         xe = 47 + i * 2, ye = 15 + i / 2;
  531.         wn_create(xs, ys, xe, ye, SGL_BDR, WN_POPUP, wnp);
  532.         wn_color( WHITE, i % 8, wnp );
  533.         wn_bdr_color( WHITE, i % 8, wnp );
  534.         sprintf(buff, "<< Window %d >>", x + 1 );
  535.         wn_name(buff, wnp);
  536.         wn_set(wnp);
  537.     }
  538.     wn_plst( CENTERED, 5, "Note that these are POPUP windows.", wnp );
  539.     wn_plst( CENTERED, 6, "Everything below them is saved.", wnp );
  540.     wn_plst( CENTERED, 7, "Watch closely as they are removed.", wnp );
  541.     wn_plst( CENTERED, 9, "<<< Don't blink or you will miss it >>>!", wnp );
  542.     wait(0);
  543.     while( x-- > 0 )
  544.         wn_destroy(wns[x]);
  545.     wn_color( LIGHTGRAY, BLUE, &Main_wn );
  546.     wn_clear(&Main_wn);
  547.     wn_prompt("Let's create and resize a window...",0);
  548.     wnp = &wn;
  549.     wn_create( 10, 4, V_cols - 11, V_rows - 5, SGL_BDR, WN_POPUP, wnp );
  550.     wn_set(wnp);
  551.     wn_set_w_wrap(1,wnp);
  552.     for( i = 0; i < 24; i+=2 )
  553.     {
  554.         wait_ticks(4L);
  555.         wn_size(10, 4, V_cols - 11 - i, V_rows - 5 - i/2, wnp );
  556.         mv_cs(0,0,wnp);
  557.         wn_st_fmt(Ww_str, wnp);
  558.     }
  559.     for( i = 23; i >= 0; i-=2 )
  560.     {
  561.         wait_ticks(4L);
  562.         wn_size(10, 4, V_cols - 11 - i, V_rows - 5 - i/2, wnp );
  563.         mv_cs(0,0,wnp);
  564.         wn_st_fmt(Ww_str, wnp);
  565.     }
  566.     wait(0);
  567.     wn_destroy(wnp);
  568. }
  569. /*** end of wn_create_demo ***/
  570.  
  571. /*******************/
  572. /* ~wn_scroll_demo */
  573. /*                 **********************************************************/
  574. /****************************************************************************/
  575. void wn_scroll_demo( void )
  576. {
  577.     int i, t, x, r;
  578.     WINDOW wn, wn1, wn2;
  579.  
  580.     wn_clear(&Main_wn);
  581.     /*--------------------- demonstrate scrolling speed ----------------------*/
  582.     wn_prompt("UltraWin has full window scrolling capabilities....",0);
  583.     wn_create( 15, 9, 59, 17, SGL_BDR, WN_NORMAL, &wn );
  584.     wn_color( YELLOW, RED, &wn );
  585.     wn_bdr_color( YELLOW, RED, &wn );
  586.     wn_name("Scrolling Window 1", &wn);
  587.     link_window(&wn);
  588.     for( t = 0; t < 2; t++ )
  589.     {
  590.         for( i = 0; i < 100; i++ )
  591.         {
  592.             wn_att(wn_get_att(&wn) & 0xf0, &wn);
  593.             wn_att(wn_get_att(&wn) | rand()%16, &wn);
  594.             wn_st("UltraWin Library ", &wn );
  595.             if( t == 0 )
  596.             wait_ticks( 1L );
  597.         }
  598.         if( t == 0 )
  599.             wn_prompt("Too slow? Let's try it at full speed!",0);
  600.     }
  601.     /*------------------------- scroll up and down ---------------------------*/
  602.     wn_prompt("There's more. UltraWin can scroll down...",0);
  603.     wn_color( YELLOW, RED, &wn );
  604.     wn_clear(&wn);
  605.     for( i = 0; i < 7; i++ )
  606.     {
  607.         mv_cs( 0, i, &wn );
  608.         wn_printf(&wn, "Line %d.....", i + 1 );
  609.     }
  610.     mv_cs(0,0,&wn);
  611.     for( i = 0; i < 7; i++ )
  612.     {
  613.         wn_csr_up(1,&wn);
  614.         wait_ticks(  2L );
  615.     }
  616.     wn_prompt("or UltraWin can scroll up.",0);
  617.     wn_clear(&wn);
  618.     for( i = 0; i < 7; i++ )
  619.     {
  620.         mv_cs( 0, i, &wn );
  621.         wn_printf(&wn, "Line %d.....", i + 1 );
  622.     }
  623.     for( i = 0; i < 7; i++ )
  624.     {
  625.         wn_csr_dn(1,&wn);
  626.         wait_ticks(  2L );
  627.     }
  628.     /*-------------------------- scrolling regions ---------------------------*/
  629.     wn_prompt("You can also set a scrolling region within a window...",0);
  630.     wn_color( YELLOW, RED, &wn );
  631.     wn_clear(&wn);
  632.     for( i = 0; i < 7; i++ )
  633.     {
  634.         mv_cs( 0, i, &wn );
  635.         wn_printf(&wn, "Line %d.....", i + 1 );
  636.     }
  637.     wn_scroll_reg( 3, 6, &wn );
  638.     wn_color(WHITE, RED, &wn);
  639.     mv_cs(0, 3, &wn);
  640.     for( i = 0; i < 50; i++ )
  641.     {
  642.         wn_st("UltraWin ", &wn );
  643.         wait_ticks(  2L );
  644.     }
  645.  
  646.     /*-------------------------- scroll multiples ---------------------------*/
  647.     wn_prompt("UltraWin can scroll multiple windows concurrently!",0);
  648.     wn_create( 12, 12, 49, 18, SGL_BDR, WN_NORMAL, &wn1 );
  649.     wn_color( WHITE, GREEN, &wn1 );
  650.     wn_bdr_color( WHITE, GREEN, &wn1 );
  651.     wn_name("Scrolling Window 2", &wn1);
  652.     wn_create( 18, 4, 69, 14, SGL_BDR, WN_NORMAL, &wn2 );
  653.     wn_color( RED, BLACK, &wn2 );
  654.     wn_bdr_color( RED, BLACK, &wn2 );
  655.     wn_name("Scrolling Window 3", &wn2);
  656.  
  657.     link_window(&wn1);
  658.     link_window(&wn2);
  659.     for( t = 0; t < 2; t++ )
  660.     {
  661.         for( i = 0; i < 100; i++ )
  662.         {
  663.             wn_st("Window 1 output ",&wn);
  664.             wn_st("Window 2 output ",&wn1);
  665.             wn_st("Window 3 output ",&wn2);
  666.             if( t == 0 )
  667.                 wait_ticks(  1L );
  668.         }
  669.         if( t == 0 )
  670.             wn_prompt("Too slow? Let's try it at full speed!",0);
  671.     }
  672.     /*----------------- scroll multiples while moving! -----------------------*/
  673.     wn_prompt("UltraWin can scroll multiple windows while moving!",0);
  674.     for( i = 0; i < 50; i++ )
  675.     {
  676.         wn_st("Window 1 output ",&wn);
  677.         wn_st("Window 2 output ",&wn1);
  678.         wn_st("Window 3 output ",&wn2);
  679.         x = rand()%10;
  680.         if( x == 1 )
  681.         {
  682.             if( wn.pane.x_min > 0 )
  683.                 wn.pane.x_min--, wn.pane.x_max--, r = 1;
  684.         }
  685.         else if( x == 2 )
  686.         {
  687.             if( wn1.pane.y_min > 4 )
  688.                 wn1.pane.y_min--, wn1.pane.y_max--, r = 1;
  689.             if( wn1.pane.x_max < V_cols )
  690.                 wn1.pane.x_min++, wn1.pane.x_max++, r = 1;
  691.         }
  692.         else if( x == 3 )
  693.         {
  694.             if( wn2.pane.y_max < V_rows )
  695.                 wn2.pane.y_min++, wn2.pane.y_max++, r = 1;
  696.             if( wn2.pane.x_max < V_cols )
  697.                 wn2.pane.x_min++, wn2.pane.x_max++, r = 1;
  698.         }
  699.         if( r )
  700.         {
  701.             reset_all_masks();                    /* reset all masks and redraw all windows */
  702.             refresh_desktop();             /* since we are moving windows NOT on top */
  703.         }                               /* if the window was always on top, we can*/
  704.     }                                  /* simply use move_wn_up, etc...                    */
  705.     unlink_window(&wn);
  706.     unlink_window(&wn1);
  707.     unlink_window(&wn2);
  708.     wn_destroy(&wn);
  709.     wn_destroy(&wn1);
  710.     wn_destroy(&wn2);
  711. }
  712. /*** end of wn_scroll_demo ***/
  713.  
  714. /**************/
  715. /* ~wn_prompt */
  716. /*            ***************************************************************/
  717. /****************************************************************************/
  718. void wn_prompt( char *prompt, int mode )
  719. {
  720.     WINDOW wn;
  721.  
  722.     wn_create( 0, 0, 79, 2, DBL_BDR, WN_NORMAL, &wn );
  723.     wn_color( RED, LIGHTGRAY, &wn );
  724.     wn_bdr_color( LIGHTGRAY, BLACK, &wn );
  725.     wn_set(&wn);
  726.     wn_plst( CENTERED, 0, prompt, &wn );
  727.     wait(mode);
  728.     wn_destroy(&wn);
  729. }
  730. /*** end of wn_prompt ***/
  731.  
  732. /*********/
  733. /* ~wait */
  734. /*       ********************************************************************/
  735. /****************************************************************************/
  736. void wait(int mode)
  737. {
  738.     push(Main_wn.att);
  739.     wn_color( LIGHTGRAY, RED, &Main_wn );
  740.     mv_cs(0,21,&Main_wn);
  741.     wn_cleol(&Main_wn);
  742.     if( mode || Wait_for_key )
  743.     {
  744.         wn_plst(CENTERED, 21, "Hit any key to continue...", &Main_wn);
  745.         wait_event();
  746.     }else
  747.         wait_ticks(36L), Event.key = 0;
  748.     pop(Main_wn.att);
  749.     mv_cs(0,21,&Main_wn);
  750.     wn_cleol(&Main_wn);
  751. }
  752. /*** end of wn_prompt ***/
  753.  
  754. /*****************/
  755. /* ~title_screen */
  756. /*               ************************************************************/
  757. /* This routine does the UltraCom title screen, logo and subscription info    */
  758. /****************************************************************************/
  759. char    *Title_strs[10] =
  760. {
  761. " ██    ██  ███     ██                         ██     ██                     ",
  762. " ██▒   ██▒  ██▒    ██▒                        ██▒    ██▒  ██                ",
  763. " ██▒░  ██▒░ ██▒░████████  █ ████    ██████    ██▒░   ██▒░  ▒▒  █ ███████    ",
  764. " ██▒░  ██▒░ ██▒░ ▒▒██▒▒▒▒ ██ ▒▒▒██   ▒▒▒▒██   ██▒░   ██▒░ ██░░ ██ ▒▒▒▒▒██▒  ",
  765. " ██▒░  ██▒░ ██▒░  ░██▒░░░░██▒ ░░░▒▒ ███████▒  ██▒░   ██▒░ ██▒  ██▒ ░░░░██▒░ ",
  766. " ██▒░  ██▒░ ██▒░   ██▒░   ██▒░     ██▒▒▒▒██▒░ ██▒░   ██▒░ ██▒░ ██▒░    ██▒░ ",
  767. " ██▒░  ██▒░ ██▒░   ██▒░   ██▒░     ██▒░░░██▒░ ██▒███ ██▒░ ██▒░ ██▒░    ██▒░ ",
  768. "  ██████▒▒░█████    ███   ██▒░      █████ █▒░  ███▒███▒▒░ ██▒░ ██▒░    ██▒░ ",
  769. "   ▒▒▒▒▒▒░░ ▒▒▒▒▒    ▒▒▒   ▒▒░      ▒▒▒▒▒▒ ▒░   ▒▒▒ ▒▒▒░░  ▒▒░  ▒▒░     ▒▒░ ",
  770. "    ░░░░░░   ░░░░░    ░░░   ░░       ░░░░░░ ░    ░░░ ░░░    ░░   ░░      ░░ "
  771. };
  772. char    *Wave_strs[7] =
  773. {
  774. "        Source Available          Extended Mode Support      Timer Control  ",
  775. "  Sound Support       EGA/VGA Downloadable Fonts             Small          ",
  776. " ┌─────────┐      ╔═ Menus═╗     [Data Entry]                  │            ",
  777. " │ Windows │      ║1) Small║        $12.34              Fast───┼───Flexible ",
  778. " └─────────┘      ║2) Fast ║        09/29/90                   │            ",
  779. "                  ╚════════╝     (123) 555-1212            Compatible       ",
  780. "   Buffered Windows    Background Printing     Mouse Support                "
  781. };
  782. char    *Info_strs[6] =
  783. {
  784. "                      UltraWin V2.50 by EnQue Software                      ",
  785. "   To order large model libraries, source code, and manual, send $99.95 to: ",
  786. "                               EnQue Software                               ",
  787. "                             Route #1, Box 116C                             ",
  788. "                           Pleasant Hill, Mo. 64080                         ",
  789. "              Voice/Fax 816-987-2515    24 Hour BBS 816-353-0991            "
  790. };
  791. void title_screen( void )
  792. {
  793.     static    int offsets[6] = { 79,79,79,79,79,79 };
  794.     int             i, r, c, c1 = 7, c2 = (c1 + 9) % 16, sinx = 0;
  795.     int                x_off = (V_cols / 2) - 39;
  796.     int                y_off = (V_rows / 2) - 8;
  797.     int                len = strlen(Wave_strs[0]);
  798.     int                w_off = 0;
  799.     WINDOW        u_wn, b_wn;
  800.     uchar            b = 0, *mask, *src;
  801.  
  802.     wn_create(x_off, y_off, x_off + 77, y_off + 13, DBL_BDR, WN_POPUP, &b_wn);
  803.     wn_att((c1 << 4) | WHITE, &b_wn);
  804.     wn_bdratt((c1 << 4) | WHITE, &b_wn);
  805.     wn_set( &b_wn);
  806.     wn_create(x_off, y_off, x_off + 77, y_off + 13, NO_BDR, WN_NORMAL, &u_wn);
  807.     wn_att((c1 << 4) | WHITE, &u_wn);
  808.     wn_bdratt((c1 << 4) | WHITE, &u_wn);
  809.     wn_set( &u_wn);
  810.     wn_border(&b_wn);
  811.     wn_set_scroll(OFF,&u_wn);
  812.     wn_set_scroll(OFF,&b_wn);
  813.     mv_cs(1, 1, &u_wn);
  814.     wn_qch(len, ' ', &u_wn);
  815.     for (i=0; i<10; i++)
  816.         wn_plst(1, i + 2, Title_strs[i], &u_wn);
  817.     mv_cs(1, 12, &u_wn);
  818.     wn_qch(len, ' ', &u_wn);
  819.  
  820.     mask = b_wn.mask;
  821.     src =  u_wn.buff;
  822.     for( r = 0; r < wn_get_rows(&b_wn); r++ )
  823.         for( c = 0; c < wn_get_cols(&b_wn); c++, mask++, src+=2 )
  824.             if ( ((*src != ' ') && (*src != 0)) )
  825.                 *mask += 1;
  826.     wn_set_mask_on(ON,&b_wn);
  827.     while ( !check_key() )
  828.     {
  829.         if( !(Tics % 5) )
  830.         {
  831.             if( sinx < 6 )
  832.             {
  833.                 if( offsets[sinx] >= 0 )
  834.                 {
  835.                     mv_cs(offsets[sinx]--, 15 + sinx,  &Main_wn);
  836.                     wn_st_qty(Info_strs[sinx], 79 - offsets[sinx], &Main_wn);
  837.                 }else
  838.                     sinx++;
  839.             }
  840.             if ((++b) >= (uchar) len)
  841.             {
  842.                 b = 0;
  843.                 c1 = (c1 + 1) % 8;
  844.                 c2 = (c1 + 9) % 16;
  845.                 wn_att((c1 << 4) | WHITE, &b_wn);
  846.                 wn_bdratt((c1 << 4) | WHITE, &b_wn);
  847.                 wn_border(&b_wn);
  848.                 wn_att((c1 << 4) | c2, &u_wn);
  849.                 mv_cs(1, 1, &u_wn);
  850.                 wn_qch(len, ' ', &u_wn);
  851.                 for (i=0; i<10; i++)
  852.                     wn_plst(1, i + 2, Title_strs[i], &u_wn);
  853.                 mv_cs(1, 12, &u_wn);
  854.                 wn_qch(len, ' ', &u_wn);
  855.                 if( ++w_off >= 6 )
  856.                     w_off = 0;
  857.             }
  858.             for( i = 0; i < 7; i++ )
  859.             {
  860.                 mv_cs(0, i + w_off, &b_wn);
  861.                 if (len - b)
  862.                     wn_st_qty(&Wave_strs[i][b], len - b, &b_wn);
  863.                 if (b)
  864.                     wn_st_qty(&Wave_strs[i][0], b, &b_wn);
  865.             }
  866.         }
  867.     }
  868.     for (i=0; i<6; i++)
  869.         wn_plst(0, 15 + i, Info_strs[i], &Main_wn);
  870.     wait_event();
  871.     wn_clear(&u_wn);
  872.     wn_border(&b_wn);
  873.     for( i = 0; i < 7; i++ )
  874.         wn_plst(1, i + 3, &Wave_strs[i][0], &u_wn);
  875.     wait(0);
  876.     wn_clear(&Main_wn);
  877.     wn_destroy(&u_wn);
  878.     wn_destroy(&b_wn);
  879. }
  880. /*** end of title_screen ***/
  881.  
  882. /*****************/
  883. /* ~wn_menu_demo */
  884. /*               ************************************************************/
  885. /* This routine demonstrates UltraWin's menuing capabilities...                         */
  886. /* the main polling loop!                                                                                                        */
  887. /****************************************************************************/
  888. int wn_menu_demo( void )
  889. {
  890.     int id, i;
  891.     uchar back_att    = (LIGHTGRAY << 4) | BLACK,
  892.                 bdr_att        = (LIGHTGRAY << 4) | BLACK,
  893.                 csr_att        = (CYAN << 4) | YELLOW,
  894.                 first_att    = (LIGHTGRAY << 4) | RED;
  895.  
  896.     wn_clear(&Main_wn);
  897.     /*-------------------- demonstrate menuing capabilities ------------------*/
  898.     wn_prompt("Use the arrow keys or your mouse to traverse the menu tree!",0);
  899.  
  900.     /*------------------------- create top menu ------------------------------*/
  901.     menu_create(0, 4, V_cols - 1, 3, M_HORIZONTAL,
  902.                             back_att, bdr_att, csr_att, first_att,
  903.                             NO_BDR, WN_NORMAL, Top_mnp);
  904.     item_add( "   Files   ", 1, 3, &Top_menu );
  905.     item_add( " Terminals ", 2, 1, &Top_menu );
  906.     item_add( "   Setup   ", 3, 3, &Top_menu );
  907.     item_add( "  Windows  ", 4, 2, &Top_menu );
  908.  
  909.     Drop_mnps[0] = &Files_menu;
  910.     Drop_mnps[1] = &Terminal_menu;
  911.     Drop_mnps[2] = &Setup_menu;
  912.     Drop_mnps[3] = &Window_menu;
  913.     /*------------------------ create file menu ------------------------------*/
  914.     menu_create(0, 5, 21, 12, M_VERTICAL,
  915.         back_att, bdr_att, csr_att, first_att,
  916.         SGL_BDR, WN_NORMAL, Drop_mnps[0]);
  917.     item_add( " Text Editor   Alt-E",    5, 6, &Files_menu );
  918.     item_add( " Hex Editor    Alt-H",    6, 1, &Files_menu );
  919.     item_add( " File Manager  Alt-F",    7, 1, &Files_menu );
  920.     item_add( " Calculator    Alt-C",    8, 1, &Files_menu );
  921.     item_add( " Dos Shell     Alt-O",    9, 5, &Files_menu );
  922.     item_add( " Quit          Alt-Q",10, 1, &Files_menu );
  923.  
  924.     /*----------------------- create terminal menu ---------------------------*/
  925.     menu_create(11, 5, 32, 11, M_VERTICAL,
  926.      back_att, bdr_att, csr_att, first_att, SGL_BDR, WN_NORMAL, Drop_mnps[1]);
  927.     item_add( " Add Terminal  Alt-T",     11, 1, &Terminal_menu );
  928.     item_add( " Settings      Alt-F6", 12, 1, &Terminal_menu );
  929.     item_add( " Receive File  Alt-F7", 13, 1, &Terminal_menu );
  930.     item_add( " Transmit File Alt-F8", 14, 1, &Terminal_menu );
  931.     item_add( " Comm Status   Alt-S",     15, 6, &Terminal_menu );
  932.  
  933.     /*-------------------------- create setup menu ---------------------------*/
  934.     menu_create(22, 5, 43,10, M_VERTICAL,
  935.         back_att, bdr_att, csr_att, first_att, SGL_BDR, WN_NORMAL, Drop_mnps[2]);
  936.     item_add( " Mouse Setup        ",    16, 1, &Setup_menu);
  937.     item_add( " Video Mode    Alt-V", 17, 1, &Setup_menu );
  938.     item_add( " Window Color  Alt-W",    18, 1, &Setup_menu );
  939.     item_add( " Border Color  Alt-B", 19, 1, &Setup_menu );
  940.  
  941.     /*-------------------------- create window menu --------------------------*/
  942.     menu_create(33, 5, 48, 9, M_VERTICAL,
  943.         back_att, bdr_att, csr_att, first_att,  SGL_BDR, WN_NORMAL, Drop_mnps[3]);
  944.     item_add( " Delete  Alt-D",    20, 1, &Window_menu );
  945.     item_add( " Size    Alt-S",    21, 1, &Window_menu );
  946.     item_add( " Move    Alt-M",    22, 1, &Window_menu );
  947.  
  948.     /*----------------------------- let's roll -------------------------------*/
  949.     wn_create( 0, 4, V_cols - 1, V_rows - 4, SGL_BDR, WN_NORMAL, Back_wnp );
  950.     wn_color( WHITE, RED, Back_wnp );
  951.     wn_bdr_color( WHITE, RED, Back_wnp );
  952.     link_window(Back_wnp);
  953.     menu_set(Top_mnp);
  954.     m_show();
  955.     set_idle_func(background_func);
  956.     id = menu_system(Top_mnp, Drop_mnps, 0);
  957.     set_idle_func(NULL);
  958.     m_hide();
  959.     menu_restore(Top_mnp);
  960.     unlink_window(Back_wnp);
  961.     wn_destroy(Back_wnp);
  962.     menu_destroy(Top_mnp);                                                        /* destroy all menus!        */
  963.     for( i = 0; i < 4; i++ )
  964.         menu_destroy(Drop_mnps[i]);
  965.     return(id);
  966. }
  967. /*** end of wn_menu_demo ***/
  968.  
  969. /********************/
  970. /* ~background_func */
  971. /*                  *********************************************************/
  972. /* This is the function we pass set_idle_func to do the background stuff!     */
  973. /* We just output to the Back_wnp global window piointer some colored text. */
  974. /****************************************************************************/
  975. int background_func( void )
  976. {
  977.     int att;
  978.  
  979.     if( !(Tics % 10) )
  980.     {
  981.         att = wn_get_att(Back_wnp) & 0x0f;                            /* roll through colors  */
  982.         att = (att + 1) % 16;
  983.         if( att == RED )
  984.             att = (att + 1) % 16;
  985.         wn_att(wn_get_att(Back_wnp) & 0xf0, Back_wnp);
  986.         wn_att(wn_get_att(Back_wnp) | att,  Back_wnp);
  987.         m_hide();
  988.         wn_st("UltraWin Library. Power, Speed, Ease!   ", Back_wnp );
  989.         m_show();
  990.     }
  991.     return(1);
  992. }
  993. /*** end of background_func ***/
  994.  
  995. /******************/
  996. /* ~wn_change_att */
  997. /*                ***********************************************************/
  998. /* This routine changes the color of a window...                                        */
  999. /* This demonstrates low level window control...                                                        */
  1000. /****************************************************************************/
  1001. void wn_change_att( uchar new_att, uchar old_att, WINDOW *wnp )
  1002. {
  1003.     int i, cnt;
  1004.     uchar *dest = wnp->buff;
  1005.  
  1006.     old_att  = get_att(old_att);
  1007.     new_att  = get_att(new_att);
  1008.     cnt = wn_get_rows(wnp) * wn_get_cols(wnp);
  1009.     dest++;
  1010.     for( i = 0; i < cnt; i++, dest += 2 )
  1011.         if( *dest == (uchar) old_att )
  1012.             *dest = new_att;
  1013.     wn_border( wnp );
  1014.     wn_rfsh( wnp );
  1015. }
  1016. /*** end of wn_change_att ***/
  1017.  
  1018. /*****************/
  1019. /* ~wn_font_demo */
  1020. /*               ************************************************************/
  1021. /* This routine shows the various font capabilities in EGA/VGA...                      */
  1022. /****************************************************************************/
  1023. void wn_font_demo( void )
  1024. {
  1025.     int i, r, c, x;
  1026.     WINDOW wn;
  1027.  
  1028.     push(Font_spacing);
  1029.     wn_clear(&Main_wn);
  1030.     if( (Font8x14 = (uchar *) calloc(256,14)) == NULL )
  1031.     {
  1032.         wn_printf(&Main_wn,"Sorry, not enough memory to allocate font!");
  1033.         wait(0);
  1034.         return;
  1035.     }
  1036.     if( !EgaVga )
  1037.     {
  1038.         wn_plst( CENTERED, 3,
  1039.             "Sorry, cannot demonstrate fonts on a non-EGA/VGA compatible adapter",
  1040.             &Main_wn );
  1041.         wait_ticks(18L*3L);
  1042.         return;
  1043.     }
  1044.     /*------------------- demonstrate font capabilities... -------------------*/
  1045.     wn_prompt("UltraWin has multiple text font capabilities....",0);
  1046.     wn_create( 30, 4, 50, 23, SGL_BDR, WN_NORMAL, &wn );
  1047.     wn_color( YELLOW, RED, &wn );
  1048.     wn_bdr_color( LIGHTGRAY, RED, &wn );
  1049.     wn_name("Font Window", &wn);
  1050.     link_window(&wn);
  1051.  
  1052.     for( i = 0; i < 4; i++ )
  1053.     {
  1054.         wn_clear(&wn);
  1055.         switch( i )
  1056.         {
  1057.             case 1:
  1058.                 setmem( Font8x14, 256*14, 0 );
  1059.                 install_font( Font8x14, 0, 0, 256, 14, 0 );
  1060.                 rom8x8(0,0);
  1061.                 break;
  1062.             case 2:
  1063.                 rom8x14(0,0);
  1064.                 break;
  1065.             case 3:
  1066.                 wn_plst(CENTERED, 0, "Now we have 512 unique characters on the screen at one time!", &Main_wn);
  1067.                 load_font( Font8x14, "8x14icon.fnt" );
  1068.                 if( Vga )
  1069.                         rom8x14(0,1), rom8x14(1,1), mv_csr(0,80);
  1070.                 install_font( Font8x14, 1, 0, 256, 14, 0 );
  1071.                 set_block_ab(0,1);
  1072.                 break;
  1073.         }
  1074.         Font_spacing = 14;
  1075.         for( x = r = 0; r < 16; r++ )
  1076.             for( c = 0; c < 16; c++,x++ )
  1077.                 mv_cs( c, r, &wn ), wn_ch((uchar) x, &wn);
  1078.         wait(0);
  1079.     }
  1080.     if( Vga )
  1081.         rom8x16(0,1), rom8x16(1,1), mv_csr(0,80);
  1082.     else
  1083.         rom8x14(0,0);
  1084.     set_block_ab(0,0);
  1085.     free(Font8x14);
  1086.     unlink_window(&wn);
  1087.     wn_destroy(&wn);
  1088.     pop(Font_spacing);
  1089. }
  1090. /*** end of wn_font_demo ***/
  1091.  
  1092. /******************/
  1093. /* ~wn_print_demo */
  1094. /*                ***********************************************************/
  1095. /*                                                                          */
  1096. /* Here we demostrate the capabilities of the background/dynamic printing   */
  1097. /* routines...                                                              */
  1098. /*                                                                          */
  1099. /* NOTE: All output will be directed to DOS files "out1.prt" & "out2.prt"   */
  1100. /*                                                                          */
  1101. /*                                                                          */
  1102. /* 1) First we set up a 1k ram based print queue that is allowed to "grow"  */
  1103. /*    up to 8k.  As the queue is emptied, it automatically shrinks,        */
  1104. /*    thereby minimizing memory usage. Note that the queue can be setup     */
  1105. /*    with an initial size equal to it's maximum size so that the dynamic   */
  1106. /*    sizing does not occur.                                                */
  1107. /*                                                                          */
  1108. /* 2) Next, we use a 128k disk based queue, requiring no memory, save a     */
  1109. /*    small amount of stack space, and print out the exact same data...     */
  1110. /*                                                                                                                                                    */
  1111. /* 3) Last, but not least, we will output to both the ram based and disk    */
  1112. /*    based queues at the same time!                                        */
  1113. /****************************************************************************/
  1114. void wn_print_demo( void )
  1115. {
  1116.     int i, c, x;
  1117.     char buffer[81];
  1118.     ulong start, end;
  1119.     long secs;
  1120.     PRINT *p[2];
  1121.  
  1122.     wn_clear(&Main_wn);
  1123.     wn_prompt("UltraWin has background printing support!",0);
  1124.  
  1125.     wn_plst( CENTERED, 2, "Welcome to the UltraWin Printer Facilities!", &Main_wn );
  1126.     wn_plst( CENTERED, 4, "This demo will setup two printers, both    ", &Main_wn );
  1127.     wn_plst( CENTERED, 5, "outputting to DOS files.  The first one is ", &Main_wn );
  1128.     wn_plst( CENTERED, 6, "a dynamically sizing ram queue that will   ", &Main_wn );
  1129.     wn_plst( CENTERED, 7, "grow up to 8k, and shrink back to 1k when  ", &Main_wn );
  1130.     wn_plst( CENTERED, 8, "drained.  Ram based queues can be up to    ", &Main_wn );
  1131.     wn_plst( CENTERED, 9, "64k.  The second is a 32k disk based queue ", &Main_wn );
  1132.     wn_plst( CENTERED,10, "that requires virtually no memory at all.  ", &Main_wn );
  1133.     wn_plst( CENTERED,11, "Queues of this nature can be of any size up", &Main_wn );
  1134.     wn_plst( CENTERED,12, "to 2 Gigabytes!  First we will print 8k    ", &Main_wn );
  1135.     wn_plst( CENTERED,13, "to each queue separately, then to both     ", &Main_wn );
  1136.     wn_plst( CENTERED,14, "concurrently.  Watch the status update as  ", &Main_wn );
  1137.     wn_plst( CENTERED,15, "the data is printed in the background.     ", &Main_wn );
  1138.  
  1139. /*--------- initialize both a ram based and disk based print queue ---------*/
  1140.     if( !init_printer("out1.prt", NULL, 1024L, 8192L, &Printer1) )
  1141.     {
  1142.         tone(1024,10);
  1143.         return;
  1144.     }
  1145.     if( !init_printer("out2.prt", "disk.buf", 32768L, 32768L, &Printer2) )
  1146.     {
  1147.         tone(1024,10);
  1148.         return;
  1149.     }
  1150.     p[0] = &Printer1;
  1151.     p[1] = &Printer2;
  1152.     set_idle_func(print_in_bkgrnd);                /* wait event will call this for us */
  1153.     wait(0);
  1154.  
  1155.     for( i = 0; i < 2; i++ )
  1156.     {
  1157.         wn_create( 2, 6 + (i*8) + i, V_cols-3, 12 + (i*8) + i, SGL_BDR, WN_POPUP, &Print_wn[i] );
  1158.         wn_color( LIGHTGRAY, RED, &Print_wn[i] );
  1159.         wn_bdr_color( LIGHTGRAY, RED, &Print_wn[i] );
  1160.         sprintf( buffer, "Printer %d", i + 1 );
  1161.         wn_name(buffer, &Print_wn[i]);
  1162.         link_window(&Print_wn[i]);
  1163.     }
  1164. /*----------------------------- perform steps 1&2 --------------------------*/
  1165.     for( x = 0; x < 2; x++ )
  1166.     {
  1167.         wn_clear( &Main_wn);
  1168.         start = Tics;
  1169.         wn_plst( CENTERED, 2, "Queueing 8K bytes of data...", &Main_wn );
  1170.         p[x]->block_mode = 1;
  1171.         i = 0;
  1172.         disp_print_stats( p[x], 1, &Print_wn[x] );
  1173.         while( p[x]->cnt < 8000L )
  1174.         {
  1175.             sprintf( buffer, "This is line %4d \r", i++ );
  1176.             print_str( (uchar *) buffer, p[x] ), print_eol( p[x] );
  1177.             if( i % 100 )
  1178.                 disp_print_stats( p[x], 0, &Print_wn[x] );
  1179.             else
  1180.                 disp_print_stats( p[x], 1, &Print_wn[x] );
  1181.         }
  1182.         wn_st( "done!", &Main_wn );
  1183.         wn_plst( CENTERED, 3, "Now lets print the data...", &Main_wn );
  1184.         c = 0;
  1185.         while( (p[x]->cnt > 0L)  )
  1186.         {
  1187.             if( check_key() )
  1188.             {
  1189.                 get_key();
  1190.                 mv_cs( c++, 4, &Main_wn );
  1191.                 wn_ch( (uchar) Event.key, &Main_wn );
  1192.             }
  1193.             print_in_bkgrnd();            /* this would be called automatically if we   */
  1194.                                                             /* called wait event. Otherwise, call it as   */
  1195.                                                             /* often as you can to perform printer output.*/
  1196.             disp_print_stats( p[x], 0, &Print_wn[x] );
  1197.         }
  1198.         disp_print_stats( p[x], 1, &Print_wn[x] );
  1199.         wn_plst( CENTERED, 3, "  Now lets print the data...done!  ", &Main_wn );
  1200.         end = Tics;
  1201.         mv_cs( 20, 1, &Main_wn );
  1202.         secs = ((end - start) * 100L) / 91L;
  1203.         wn_printf( &Main_wn, "Time: = ~%ld.%02ld seconds  ~%-5d bytes/sec",
  1204.             secs / 100L, secs % 100L, (int)(800000L/secs) );
  1205.         wait(0);
  1206.     }
  1207. /*------------------------------- perform steps 3 --------------------------*/
  1208.     wn_clear( &Main_wn);
  1209.     start = Tics;
  1210.     wn_plst( CENTERED, 2, "Queueing 8K bytes of data...", &Main_wn );
  1211.     i = 0;
  1212.     disp_print_stats( p[0], 1, &Print_wn[0] );
  1213.     disp_print_stats( p[1], 1, &Print_wn[1] );
  1214.     while( p[0]->cnt < 8000L )
  1215.     {
  1216.         sprintf( buffer, "This is line %4d \r", i++ );
  1217.         print_str( (uchar *) buffer, p[0] ), print_eol( p[0] );
  1218.         print_str( (uchar *) buffer, p[1] ), print_eol( p[1] );
  1219.         if( i % 100 )
  1220.         {
  1221.             disp_print_stats( p[0], 0, &Print_wn[0] );
  1222.             disp_print_stats( p[1], 0, &Print_wn[1] );
  1223.         }else{
  1224.             disp_print_stats( p[0], 1, &Print_wn[0] );
  1225.             disp_print_stats( p[1], 1, &Print_wn[1] );
  1226.         }
  1227.     }
  1228.     wn_st( "done!", &Main_wn );
  1229.     wn_plst( CENTERED, 3, "Now lets print the data...", &Main_wn );
  1230.     c = 0;
  1231.     while( (p[0]->cnt > 0L) || (p[1]->cnt > 0L) )
  1232.     {
  1233.         if( check_key() )
  1234.         {
  1235.             get_key();
  1236.             mv_cs( c++, 1, &Main_wn );
  1237.             wn_ch( (uchar) Event.key, &Main_wn );
  1238.         }
  1239.         print_in_bkgrnd();                /* this would be called automatically if we   */
  1240.                                                             /* called wait event. Otherwise, call it as   */
  1241.                                                             /* often as you can to perform printer output.*/
  1242.         disp_print_stats( p[0], 0, &Print_wn[0] );
  1243.         disp_print_stats( p[1], 0, &Print_wn[1] );
  1244.     }
  1245.     disp_print_stats( p[0], 1, &Print_wn[0] );
  1246.     disp_print_stats( p[1], 1, &Print_wn[1] );
  1247.     wn_plst( CENTERED, 3, "  Now lets print the data...done!  ", &Main_wn );
  1248.     end = Tics;
  1249.     mv_cs( 20, 1, &Main_wn );
  1250.     secs = ((end - start) * 100L) / 91L;
  1251.     wn_printf( &Main_wn, "Time: = ~%ld.%02ld seconds  ~%-5d bytes/sec",
  1252.         secs / 100L, secs % 100L, (int)(1600000L/secs) );
  1253.     wait(0);
  1254.     /*------------------------------------------------------------------------*/
  1255.  
  1256.     unlink_window(&Print_wn[0]);
  1257.     wn_destroy(&Print_wn[0]);
  1258.     unlink_window(&Print_wn[1]);
  1259.     wn_destroy(&Print_wn[1]);
  1260.     end_printer( &Printer1 );
  1261.     end_printer( &Printer2 );
  1262.     wn_clear(&Main_wn);
  1263. }
  1264. /*** end of wn_print_demo ***/
  1265.  
  1266. /*********************/
  1267. /* ~disp_print_stats */
  1268. /*                   *******************************************************/
  1269. /*  This routine prints important variables in the printer structure to the*/
  1270. /*    desired window and is used primarily for debugging.  If the mode is    */
  1271. /*    1, all variables are printed, if 0, only the Read, Write, and Cnt are  */
  1272. /*    printed for speed.                                                     */
  1273. /*                                                                         */
  1274. /* Device:lpt1                                  Buffer:   disk.buf         */
  1275. /* Read  :    4343     Init Size:     2000      Active:1      CR  :1       */
  1276. /* Write :    6648     Max  Size:    32000      Halt  :1      LF  :2       */
  1277. /* Cnt   :    2345     Curr Size:    16000      Block :1      Xlat:0       */
  1278. /***************************************************************************/
  1279. void disp_print_stats( PRINT *p, int mode, WINDOW *wnp )
  1280. {
  1281.     mv_cs( 0, 1, wnp );
  1282.     wn_printf( wnp, "Read  :%8ld", p->read  );
  1283.     mv_cs( 0, 2, wnp );
  1284.     wn_printf( wnp, "Write :%8ld", p->write );
  1285.     mv_cs( 0, 3, wnp );
  1286.     wn_printf( wnp, "Cnt   :%8ld", p->cnt   );
  1287.     if( mode )
  1288.     {
  1289.         mv_cs( 0, 0, wnp );
  1290.         wn_printf( wnp, "Device:%-20s   Buffer:%-20s", p->device, p->buffer );
  1291.         mv_cs( 20, 1, wnp );
  1292.         wn_printf( wnp, "Init Size:%8ld    Active:%d    CR  :%d",
  1293.             p->init_que_size, p->active, p->cr_cnt );
  1294.         mv_cs( 20, 2, wnp );
  1295.         wn_printf( wnp, "Max  Size:%8ld    Halt  :%d    LF  :%d",
  1296.             p->max_que_size, p->halt, p->lf_cnt  );
  1297.         mv_cs( 20, 3, wnp );
  1298.         wn_printf( wnp, "Curr Size:%8ld    Block :%d    Xlat:%d",
  1299.             p->curr_que_size, p->block_mode, p->xlat_flag );
  1300.     }
  1301. }
  1302. /*** end of disp_print_stats ***/
  1303.  
  1304. /**** END OF FILE ****/
  1305.  
  1306.